# -*- coding:utf-8 -*-
# @FileName  :dhcc_ent_3_archivequery.py
# @Time      :2020/12/21 16:03
# @Author    :Zhoujirong
# @Desc      : 授权信息查看
import datetime,time
from common.log import Log
from biz.flow.ent_archivequery import EntArchiveQueryRequst
from biz.cases.base_case import BaseCase
from common.utils import download
from biz.flow.ent_reqresult import EntReqResultRequest

class TestEntArchiveQuery(BaseCase):
    data_file_name = 'ent_authorize_data.yaml'
    @classmethod
    def setUpClass(cls) -> None:
        cls.cookie = BaseCase().get_token()

    def get_page(self):
        '''返回一条数据'''
        curPage = self.file_data.get('curPage')
        maxSize = self.file_data.get('maxSize')
        search_EQ_enterpriseName = self.file_data.get('enterpriseName')
        search_EQ_signCode = self.file_data.get('signCode')
        search_EQ_uniformSocialCredCode = self.file_data.get('uniformSocialCredCode')
        search_EQ_orgInstCode = self.file_data.get('orgInstCode')
        search_EQ_archiveType = self.file_data.get('archiveType')
        search_EQ_creator = self.file_data.get('search_EQ_creator')
        search_IN_ownorg = self.file_data.get('operorg')
        search_GTE_startDate_DATE = datetime.date.today()
        search_LTE_expireDate_DATE = datetime.date.today()
        ret = EntArchiveQueryRequst.get_page(curPage,
            maxSize,
            search_EQ_enterpriseName,
            search_EQ_signCode,
            search_EQ_uniformSocialCredCode,
            search_EQ_orgInstCode,
            search_EQ_archiveType,
            search_EQ_creator,
            search_IN_ownorg,
            search_GTE_startDate_DATE,
            search_LTE_expireDate_DATE,self.cookie)
        Log.info(ret)
        self.assertIsNotNone(ret.list)
        return ret.list[0].id

    def test_detail(self):
        '''跳转详情页'''
        id = self.get_page()
        ret = EntArchiveQueryRequst.detail(id,self.cookie)
        Log.info(ret)
        self.assertIn('企业名称',ret)

    def test_findbyid(self):
        '''详情'''
        id = self.get_page()
        ret = EntArchiveQueryRequst.findbyid(id,self.cookie)
        Log.info(ret)
        self.assertEqual(id,ret.id)

    def findbyarchiveid(self):
        '''授权文件详情'''
        archiveId = self.get_page()
        ret = EntReqResultRequest.findbyarchiveid(archiveId,self.cookie)
        Log.info(ret)
        return ret[0]['id'],ret[1]['id'],ret[2]['id'],ret[3]['id']

    def test_getpicturefile1(self):
        '''电子文件详情1'''
        id1,id2,id3,id4 = self.findbyarchiveid()
        ret = EntArchiveQueryRequst().getpicturefile(id1,self.cookie)
        Log.info(ret)
        size = download('企业电子档案1dhcc_ent_3_archivequeryDtest_getpicturefile1%s.png'%time.strftime('%Y%m%d%H%M%S',time.localtime()),ret)
        Log.info('文件大小为:%s' % size)
        self.assertNotEqual(0, size)

    def test_getpicturefile2(self):
        '''电子文件详情2'''
        id1,id2,id3,id4 = self.findbyarchiveid()
        ret = EntArchiveQueryRequst().getpicturefile(id2,self.cookie)
        Log.info(ret)
        size = download('企业电子档案2dhcc_ent_3_archivequeryDtest_getpicturefile2%s.png' % time.strftime('%Y%m%d%H%M%S', time.localtime()), ret)
        Log.info('文件大小为:%s' % size)
        self.assertNotEqual(0, size)

    def test_getpicturefile3(self):
        '''电子文件详情3'''
        id1,id2,id3,id4 = self.findbyarchiveid()
        ret = EntArchiveQueryRequst().getpicturefile(id2,self.cookie)
        Log.info(ret)
        size = download('企业电子档案3dhcc_ent_3_archivequeryDtest_getpicturefile3%s.jpg' % time.strftime('%Y%m%d%H%M%S', time.localtime()), ret)
        Log.info('文件大小为:%s' % size)
        self.assertNotEqual(0, size)

    def test_getpicturefile4(self):
        '''电子文件详情4'''
        id1,id2,id3,id4 = self.findbyarchiveid()
        ret = EntArchiveQueryRequst().getpicturefile(id4, self.cookie)
        Log.info(ret)
        size = download('企业电子档案4dhcc_ent_3_archivequeryDtest_getpicturefile4%s.jpg' % time.strftime('%Y%m%d%H%M%S', time.localtime()), ret)
        Log.info('文件大小为:%s' % size)
        self.assertNotEqual(0, size)

    def test_export_one(self):
        '''导出一条数据'''
        ids = self.get_page()
        search_EQ_enterpriseName = self.file_data.get('enterpriseName')
        search_EQ_signCode = self.file_data.get('signCode')
        search_EQ_uniformSocialCredCode = self.file_data.get('uniformSocialCredCode')
        search_EQ_orgInstCode = self.file_data.get('orgInstCode')
        search_EQ_archiveType = self.file_data.get('archiveType')
        search_EQ_creator = self.file_data.get('search_EQ_creator')
        search_IN_ownorg = self.file_data.get('operorg')
        search_GTE_startDate_DATE = datetime.date.today()
        search_LTE_expireDate_DATE = datetime.date.today()
        ret = EntArchiveQueryRequst.export(
            search_EQ_enterpriseName,
            search_EQ_signCode,
            search_EQ_uniformSocialCredCode,
            search_EQ_orgInstCode,
            search_EQ_archiveType,
            search_EQ_creator,
            search_IN_ownorg,
            search_GTE_startDate_DATE,
            search_LTE_expireDate_DATE,ids,self.cookie)
        Log.info(ret)
        size = download('企业授权信息单条dhcc_ent_3_archivequeryDtest_export_one%s.xls'%time.strftime('%Y%m%d%H%M%S',time.localtime()),ret)
        Log.info('文件大小为:%s' % size)
        self.assertNotEqual(0, size)

    def test_export_all(self):
        '''导出全部'''
        ids = ''
        search_EQ_enterpriseName = ''
        search_EQ_signCode = ''
        search_EQ_uniformSocialCredCode = ''
        search_EQ_orgInstCode = ''
        search_EQ_archiveType = ''
        search_EQ_creator = ''
        search_IN_ownorg = ''
        search_GTE_startDate_DATE = ''
        search_LTE_expireDate_DATE = ''
        ret = EntArchiveQueryRequst.export(search_EQ_enterpriseName,
            search_EQ_signCode,
            search_EQ_uniformSocialCredCode,
            search_EQ_orgInstCode,
            search_EQ_archiveType,
            search_EQ_creator,
            search_IN_ownorg,
            search_GTE_startDate_DATE,
            search_LTE_expireDate_DATE,ids,self.cookie)
        Log.info(ret)
        size = download('企业授权信息alldhcc_ent_3_archivequeryDtest_export_all%s.xls'%time.strftime('%Y%m%d%H%M%S',time.localtime()),ret)
        Log.info('文件大小为:%s' % size)
        self.assertNotEqual(0, size)

    def get_page_more(self):
        '''返回2条数据'''
        curPage = self.file_data.get('curPage')
        maxSize = self.file_data.get('maxSize')
        search_EQ_enterpriseName = ''
        search_EQ_signCode = ''
        search_EQ_uniformSocialCredCode = ''
        search_EQ_orgInstCode = ''
        search_EQ_archiveType = ''
        search_EQ_creator = ''
        search_IN_ownorg = ''
        search_GTE_startDate_DATE = ''
        search_LTE_expireDate_DATE = ''
        ret = EntArchiveQueryRequst.get_page(curPage,
                                            maxSize,
                                            search_EQ_enterpriseName,
                                            search_EQ_signCode,
                                            search_EQ_uniformSocialCredCode,
                                            search_EQ_orgInstCode,
                                            search_EQ_archiveType,
                                            search_EQ_creator,
                                            search_IN_ownorg,
                                            search_GTE_startDate_DATE,
                                            search_LTE_expireDate_DATE,self.cookie)
        Log.info(ret)
        self.assertIsNotNone(ret.list)
        return '%s,%s'%(ret.list[0].id,ret.list[1].id)

    def test_export_more(self):
        '''导出2条'''
        ids = self.get_page_more()
        search_EQ_enterpriseName = ''
        search_EQ_signCode = ''
        search_EQ_uniformSocialCredCode = ''
        search_EQ_orgInstCode = ''
        search_EQ_archiveType = ''
        search_EQ_creator = ''
        search_IN_ownorg = ''
        search_GTE_startDate_DATE = ''
        search_LTE_expireDate_DATE = ''
        ret = EntArchiveQueryRequst.export(search_EQ_enterpriseName,
                                            search_EQ_signCode,
                                            search_EQ_uniformSocialCredCode,
                                            search_EQ_orgInstCode,
                                            search_EQ_archiveType,
                                            search_EQ_creator,
                                            search_IN_ownorg,
                                            search_GTE_startDate_DATE,
                                            search_LTE_expireDate_DATE,ids,self.cookie)
        Log.info(ret)
        size = download('企业授权信息2条dhcc_ent_3_archivequeryDtest_export_more%s.xls'%time.strftime('%Y%m%d%H%M%S',time.localtime()),ret)
        Log.info('文件大小为:%s' % size)
        self.assertNotEqual(0, size)










if __name__ == "__main__":
    pass